home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
c_flow.zip
/
CFLOW.C
next >
Wrap
Text File
|
1985-06-24
|
27KB
|
1,205 lines
/*
** CFLOW.C : find module call structure of c program
** refer to cflow.doc for how to use
**
** Mark Ellington
** 05-27-84
**
** Converted to MS-DOS 2 and C86, adding the following features:
**
** 1. filename wildcard support
** 2. -l flag to include line numbers in output
** 3. -f flag to include file names in output
** 4. #include support (with -h flag, same as C86 V2.20H)
** 5. -x flag to generate input for CFLOWX
** 6. #define macro() support
** 7. -t flag to change to '\t' for indentation
** 8. -s flag to allow specification of number of indentation spaces
** (default is 4 spaces)
**
** Larry Steeger
** 06-12-85
*/
#include <stdio.h> /* C86 header */
#define VOID int
/* external functions */
extern VOID abort();
extern char *alloc();
extern VOID exit();
extern int fclose();
extern unsigned char *filewdir();
extern FILE *fopen();
extern VOID fprintf();
extern int fputs();
extern VOID free();
extern int isalnum();
extern int isdigit();
extern int isspace();
extern char *lower();
extern char *makefile();
extern char *makefnam();
extern char *makepath();
extern char *realloc();
extern VOID setmem();
extern VOID sprintf();
extern char *strcat();
extern unsigned char *strchr();
extern char *strcpy();
extern unsigned strlen();
extern int strncmp();
extern char *strncpy();
extern int tolower();
#include "cflowx.h" /* CFLOW/CFLOWX header */
#define VERSION 85
#define RELEASE 06
#define MODIFIC 20
#define outinfo(S) fputs(S,stdout)
/* display CFLOW logo */
outlogo()
{
outinfo("\nCFLOW --> function declarations and calls in C source");
outinfo("\nby Mark Ellington");
fprintf(stdout,
"\n[V%02d.%02d.%02d for C86 by Lawrence R. Steeger]\n",
VERSION, RELEASE, MODIFIC
);
}
/* CFLOW usage help */
outhelp()
{
outinfo("\n usage: cflow ");
outinfo("[-[lft]|[x]] [-hsystem[,project]] ");
outinfo("[input1[..inputn]] [>output]\n");
outinfo("\n flags: -hsystem[,project]");
outinfo("\n #include drive/pathname specification");
outinfo("\n (usage: C86 V2.20H)");
outinfo("\n -l include line numbers in output");
outinfo("\n -f include file names in output");
outinfo("\n -sn number of indentation spaces");
outinfo("\n -t tabs rather than spaces for indentation");
outinfo("\n -x generate input for CFLOWX\n");
outinfo("\ndefaults: cflow -s4 [input] >stdout");
}
typedef struct _cflow { /* recursive execution structure */
struct _cflow *_chain; /* previous CFLOW structure */
int _fnmbr, /* current file name index */
_level, /* level of open "{"s or #includes */
_prevchar, /* previous character in input buffer */
_curchar, /* current character in input buffer
** array subscript
*/
_curline, /* current line in input dataset */
_define, /* #define flag */
_defdcl; /* name declaration offset */
unsigned char _delimit, /* #include file name delimiter */
*_defname,/* defined name buffer */
*_name, /* module name buffer */
*_ins, /* source input line buffer */
*_fname, /* source file name buffer */
*_fpname; /* source file/pathname buffer */
FILE *_fptr; /* input file pointer */
} CFLOW;
/* useability macros for CFLOW structure elements */
#define chain cflowp->_chain
#define fnmbr cflowp->_fnmbr
#define level cflowp->_level
#define prevchar cflowp->_prevchar
#define curchar cflowp->_curchar
#define curline cflowp->_curline
#define define cflowp->_define
#define defdcl cflowp->_defdcl
#define delimit cflowp->_delimit
#define defname cflowp->_defname
#define name cflowp->_name
#define ins cflowp->_ins
#define fname cflowp->_fname
#define fpname cflowp->_fpname
#define fptr cflowp->_fptr
/* runtime flags */
static int hflag = FALSE, /* -h #include drive/pathname */
lflag = FALSE, /* -l show line numbers */
fflag = FALSE, /* -f show file names */
sflag = FALSE, /* -s space indentation count */
tflag = FALSE, /* -t tab indentation flag */
xflag = FALSE; /* -x generate CFLOWX input */
static int fnumber = 0, /* C source file counter */
flevel = 0, /* C source file level */
mnumber = 0; /* C source file main counter */
static unsigned char *filepath = NULL, /* default file/path name */
*hsystem = NULL, /* -hsystem specification */
*hproject = NULL, /* -h,project specification */
*tab = " "; /* -t indentation */
static unsigned char newLine[] = {"\n"};
static CFLOW *cflowp = NULL; /* current CFLOW execution ptr */
/* mainline */
main(argc,argv)
int argc;
unsigned char * argv[];
{
unsigned char *fp,
*pp; /* temporary file/path pointer */
int fcount, /* C source file counter */
i,
j;
if (argc < 2) { /* display CFLOW help */
outlogo();
outhelp();
exit(1);
}
cflowp = alloc(sizeof(CFLOW)); /* 1st execution structure */
name = alloc(MAXBUF); /* module name buffer */
ins = alloc(MAXBUF); /* input line buffer */
fname = alloc(MAXPATH); /* current file name */
fpname = alloc(MAXPATH); /* current file/path name */
filepath = alloc(1); /* dummy file/path name */
*filepath = EOS;
for (i=1; i < argc; i++) { /* process all flags */
if (*argv[i] == '-') {
flags(argv[i]);
for (j = i--, --argc; j < argc; j++)
argv[j] = argv[j+1];
}
}
if (!xflag) outlogo(); /* display CFLOW logo */
if (hsystem != NULL) /* display -h system prefix */
if (*hsystem)
output(HDRSYST, hsystem);
if (hproject != NULL) /* display -h project prefix */
if (*hproject)
output(HDRPROJ, hproject);
for (i=1; i < argc; i++) { /* process all files */
if (*argv[i]) {
fnmbr = mnumber++;
strcpy(fname, argv[i]); /* get file name */
lower(fname);
free(filepath); /* get file/path name */
filepath = makepath(fname);
if ((strchr(fname, '*') != NULL) /* wildcards */
|| (strchr(fname, '?') != NULL)) {
/* process all matching file names */
fcount = 0;
while ((fp = filewdir(argv[i],0x00)) != NULL) {
if (!fcount) {
pp = makepath(fname);
output(WILDPTH, pp);
free(pp);
pp = makefile(fname);
output(WILDNME, pp);
free(pp);
}
++fcount;
lower(fp);
strcpy(fname,fp);
makefnam(fp, filepath, fpname);
flevel = level = 0;
modules();
free(fp);
}
if (!fcount) output(WILDNF, fname);
}
else { /* no wildcards */
strcpy(fpname, fname);
strcpy(fname, (pp=makefile(fname)));
free(pp);
flevel = level = 0;
modules();
}
}
}
exit(0);
}
/* process command line flags */
int flags(flag)
unsigned char *flag;
{
unsigned char *hp;
int i;
for (i=1; i < strlen(flag); i++)
switch (tolower(flag[i])) {
case 'h': /* -h header specifications */
hflag = TRUE;
i++;
if (hsystem != NULL)
free(hsystem);
if ((hp = strchr(&flag[i], ',')) != NULL)
*hp++ = EOS;
hsystem = alloc((strlen(&flag[i]) + 1));
strcpy(hsystem, lower(&flag[i]));
if (hp) {
if (hproject != NULL)
free(hproject);
hproject = alloc((strlen(hp) + 1));
strcpy(hproject, lower(hp));
}
i=strlen(flag); /* force break in for loop */
break;
case 'l': /* -l include line numbers */
lflag = TRUE;
break;
case 'f': /* -f include file names */
fflag = TRUE;
break;
case 's': /* -s spaces for indentation */
if (tflag) {
fprintf(stdout,
"\n-s is mutually exclusive with -t");
outhelp();
exit(1);
}
if (!isdigit(flag[i+1])) { /* -s only ! */
/* note: -s implies default */
sflag = strlen(tab);
break;
}
sflag = 0;
while (isdigit(flag[++i]))
sflag = (sflag * 10) + ((int)flag[i] - '0');
--i;
if (sflag) {
tab =